/*
 * @Author: szx
 * @Date: 2021-11-12 13:01:06
 * @LastEditTime: 2021-11-12 13:40:54
 * @Description:
 * @FilePath: \leetcode\700-799\713\713.cpp
 */
#include <iostream>
#include <vector>
using namespace std;
class Solution {
   public:
    int numSubarrayProductLessThanK(vector<int>& nums, int k) {
        if (k <= 1) return 0;
        int l = 0, n = nums.size();
        int sum = 1;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            sum *= nums[i];
            while (sum >= k) {
                sum /= nums[l];
                l++;
            }
            cnt += i - l + 1;
        }
        return cnt;
    }
};
